package com.example.shixunandjavagotoyangchen.BoosYang.Day001;

import android.util.Log;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.example.modelviewpresenter.View.BasterFragment;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00188.AbstractAdpter;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00188.AbstractBean;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00188.AbstractContion;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00188.AbstractModel;
import com.example.shixunandjavagotoyangchen.BoosYang.Day001.Day00188.AbstractPresenter;
import com.example.shixunandjavagotoyangchen.R;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener;

import java.util.List;


public class BlankFragmentDay00188 extends BasterFragment  implements AbstractContion.vier, OnRefreshLoadMoreListener {

    public AbstractAdpter adpter;
    public AbstractPresenter presenter;
    public boolean ising = true;
    public  int contger=55;
    public  int kaomei =0;
    private SmartRefreshLayout AbstractSmartRefreshLayout;
    private RecyclerView AbstractRecyclerView;

    @Override
    public int BandLayout() {
        return R.layout.fragment_blank_fragment_day00188;
    }

    @Override
    public void initView() {

        AbstractSmartRefreshLayout = (SmartRefreshLayout) findViewById(R.id.Abstract_SmartRefreshLayout);
        AbstractRecyclerView = (RecyclerView) findViewById(R.id.Abstract_RecyclerView);
        AbstractRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
        AbstractSmartRefreshLayout.setOnRefreshLoadMoreListener(this);
        presenter = new AbstractPresenter(this,new AbstractModel());
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");

    }

    @Override
    public void initDate() {

    }


    @Override
    public void getvier(List<AbstractBean.DataBean> dataBeans) {
        for (AbstractBean.DataBean dataBean : dataBeans) {
            dataBean.setAbstractlayout(++kaomei);
            if (kaomei==4){
                kaomei=0;
            }
        }
        AbstractSmartRefreshLayout.finishLoadMore();
        AbstractSmartRefreshLayout.finishRefresh();
        if (adpter==null){
            adpter = new AbstractAdpter(dataBeans);
            AbstractRecyclerView.setAdapter(adpter);
        }else {
            if (ising){
                adpter.getData().clear();
            }
            adpter.getData().addAll(dataBeans);
            adpter.notifyDataSetChanged();
        }

    }


    @Override
    public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
        ising=false;
        contger++;
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");
        Log.i("BlankFragmentDay001","---00188加载:"+contger);
    }

    @Override
    public void onRefresh(@NonNull RefreshLayout refreshLayout) {
        if (ising){
            contger=70;
        }
        presenter.dogetin("/video/findVideos?currentPage="+contger+"&pageSize=10");

        Log.i("BlankFragmentDay001","---00188刷新:"+contger);
    }
}
